<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="button" onclick="on()" value="开灯">
<img id="myImage" border="0" src="images/off.gif" style="text-align:center;">
<input type="button" onclick="off()" value="关灯">

<script>
    function on(){
        document.getElementById('myImage').src='images/on.gif';
    }

    function off(){
        document.getElementById('myImage').src='images/off.gif'
    }
    var x=0;
    //定时器
    setInterval(function() {
    if (x%2==0) {
        on();
    } else {
        off();
    }
    x++;
    },1000);
</script>
</body>
</html>